<template>
	<view>
		<view class="search-view">
			<u-search bgColor="#F6F6F6"  shape="square"  placeholder="请输入地址/姓名搜索"   :showAction="false"
				v-model="keyword" @custom="search"></u-search>
		</view>
		<view v-if="list.length==0">
			<u-gap height="80"></u-gap>
			<u-empty mode="data" :icon="$imgSrc('static/images/empty.png')"></u-empty>
		</view>
		<view class="pl20 pr20 address-card" v-for="(item,index) in list" :key="index">
			<view class="bgfff path-card">
				<view class="pt20 pl24 pr20 ">
					<view class="dsf alc pb20 ">
						<image class="w22 h24" :src="$imgSrc('/static/images/path.png')"></image>
						<view class="fz28 col666 pl10 address-title">{{item.address.mapAddress}}</view>
					</view>
					<view class="pb20 pl10">
						<view class=" pb20">
							<view class="dsf alc pb20">
								<view class="fz28 col666 pl30 address-detail">
									{{item.address.mapAddressDetail}}
								</view>
							</view>
							<view class="dsf alc">
								<view class="fz28 col666 pl30">
									{{item.address.userName+' '+item.address.userPhone}}
								</view>
							</view>
						</view>
					</view>
					<view class="pb20 dsf alc relative">
						<view @click="$go('newaddress/address/editbook?id='+item.id)" class="pl30 pr30 pt10 pb10 bdra10 dsf alc  button-icon "
							style="box-shadow:0 0 20rpx rgba(0,0,0,.2);">
							<view class="fz30 col999 pl10 ">编辑</view>
						</view>
						<view class="pl30 pr30 pt10 pb10 bdra10 dsf alc button-icon ml30"
							style="box-shadow:0 0 20rpx rgba(0,0,0,.2);">
							<view @click="sDel=true;act_item=item" class="fz30 col999 pl10 ">删除</view>
						</view>
						<view v-if="is_user" @click="choose(item)" class="absolute r0">
							<view class="bg0083FE pl30 pr30 pb10 pt10 bdra10 dsf alc  ml30 button-icon ">
								<view class="fz30 colfff pl10 ">使用</view>
							</view>
						</view>


					</view>
				</view>
			</view>
		</view>
		<view class="add-box">
			<u-tabbar inactiveColor="#fff" :border="false">
				<u-tabbar-item @click="add" text="添加地址"></u-tabbar-item>
			</u-tabbar>
		</view>
		<!--删除弹窗-->
		<u-modal :show="sDel" cancelText="暂不删除" @cancel="sDel=false" @confirm="comDel" :showCancelButton="true"
			closeOnClickOverlay class="box">
			<view class="tip-text pt-30 pb-30 fz30">
				确定删除数据？
			</view>
		</u-modal>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				keyword: "",
				list: [],
				type: "",
				param: {},
				sDel: false,
				act_item: {},
				is_user: 0
			}
		},
		onLoad(e) {
			this.param = e;
			if (e.is_user) {
				this.is_user = 1;
			}
		},
		onShow() {
			this.getList();
		},

		methods: {
			comDel() {
				this.$api['del']('user/delete-address/' + this.act_item.id, {}).then(res => {
					if (res.code == 200) {
						this.sDel = false;
						this.$toast({
							title: "删除成功"
						});
						this.param.page = 1;
						this.getList();
					}
				});
			},
			getList() {
				this.$api['get']('user/get-address', this.param).then(res => {
					if (res.code == 200) {
						this.list = res.data;
					}
				});
			},
			search(){
				this.param.keyword=this.keyword;
				this.getList();
			},
			choose(row) {
				if (this.param.type == 1) {
					var idx = this.param.idx ? 0 : this.param.idx;
					idx=idx-0;
					var deliveAddress = this.$store.getters.deliveAddress;
					deliveAddress[idx] = row.address;
					if (this.param.path == 1) {
						this.$store.commit("tgetDelive", deliveAddress);
					} else {
						this.$store.commit("getDelive", deliveAddress);
					}

					//this.$store.commit("getDelive", [row.address]);
				} else {
					if (this.param.path == 1) {
						this.$store.commit("tgetReceive", row.address);
					} else {
						this.$store.commit("getReceive", row.address);
					}

				}
				if (this.param.path == 1) {
					uni.navigateTo({
						url: "/pages/newaddress/address/editpath"
					});
					return;
				}
				uni.navigateTo({
					url: "/pages/index/index"
				});
			},
			add(){
				this.$store.commit("setDelive",{});
				this.$go('newaddress/address/editbook');
			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		background-color: #eef2fd
	}

	.search-view {
		background-color: #fff;
		padding:22upx 28upx 20upx 22upx;
	}

	.path-card {
		border-radius: 20upx
	}

	.address-detail {
		color: #999
	}

	.address-card {
		padding-bottom: 10upx;
		padding-top: 10upx
	}

	.address-title {
		font-size: 32upx;
		font-weight: 700
	}

	.bgF8FAFE {
		padding-top: 20upx
	}
</style>